{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "3afc740a-bca7-4531-bd7b-de2c0686fac9",
   "metadata": {},
   "source": [
    "# Exercise: Using `Plotly` to create a simple bar chart\n",
    "\n",
    "In this exercise, you'll be practicing the same 20 and 50-day moving average chart from the `matplotlib` exercise, but using `plotly`. "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dc2d8a6d-45cc-4f2f-af57-8a330c35b307",
   "metadata": {},
   "source": [
    "**Download historical data for 2 years from one ticker**\n",
    "\n",
    "Use the YFinance package to download 2 years of data for any ticker you'd like. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4e4fd227-caf4-4fcf-a23d-0949ff32a5bf",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import yfinance as yf\n",
    "import plotly.graph_objects as go"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "40123a2e-01fe-4800-8358-9551f1ec5f5b",
   "metadata": {},
   "outputs": [],
   "source": [
    "stock_ticker = ''\n",
    "start_date = '' # use format YYYY-MM-DD\n",
    "end_date = ''\n",
    "\n",
    "data = yf.download( ... ) # replace ... inside this function with the correct parameters in order to get your data"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8f32c4c3-b803-4233-8b8c-ecb137b839dd",
   "metadata": {},
   "source": [
    "**Calculate the 20-day and 50-day moving average**\n",
    "\n",
    "Use Pandas methods to calculate the 20-day and 50-day moving averages for your ticker."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2bc98328-c44b-46a4-aff7-aad951051e0a",
   "metadata": {},
   "outputs": [],
   "source": [
    "data['MA_20'] = \n",
    "data['MA_50'] = "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6324e036-5167-4ebe-9c2b-bcdc20d4e2cd",
   "metadata": {},
   "source": [
    "**Create a chart in `plotly` that shows both the 20-day and 50-day rolling average, plus the closing price, on the same graph**\n",
    "\n",
    "Creating plots in `Plotly` takes a little more effort than in `matplotlib`. You'll be creating the same chart as you did in the prior exercise, but now using `plotly`. \n",
    "\n",
    "Can you add these 3 variables to the same line chart: (1) closing price, (2) 20-day moving average, and (3) 50-day moving average? \n",
    "\n",
    "Recall that in `plotly` each variable is added using a `trace`. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4750f340-d190-454f-982d-cf89c6159b01",
   "metadata": {},
   "outputs": [],
   "source": [
    "fig = # fill this in\n",
    "\n",
    "# add closing price\n",
    "fig.add_trace(...) # replace ...\n",
    "\n",
    "# adding 20-day moving avg\n",
    "fig.add_trace(...) # replace ...\n",
    "\n",
    "# add 50-day moving avg \n",
    "fig.add_trace(...) # replace ..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8004e51b-2811-424c-ac08-36ac98778ff7",
   "metadata": {},
   "outputs": [],
   "source": [
    "# customize your layout\n",
    "\n",
    "fig.update_layout(\n",
    "        title = '',\n",
    "        xaxis_title = '',\n",
    "        yaxis_title = '',\n",
    "        template = ''\n",
    ")\n",
    "\n",
    "fig.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
